package cn.edu.lingnan.utils;

import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 连接数管理类，用于统计当前活跃的 WebSocket 连接数。
 */
@Component
public class ConnectionCounter {

    private final AtomicInteger activeConnections = new AtomicInteger(0);

    public void increment() {
        activeConnections.incrementAndGet();
    }

    public void decrement() {
        activeConnections.decrementAndGet();
    }

    public int getActiveConnections() {
        return activeConnections.get();
    }
}
